<?php

require_once "Default.php";

class MetadataCollector {

    private $foundExportNames = array();
    private $foundMetadata = array();
    /**
     *
     * @var ReflectionClass
     */
    private $type;
    private $returnValue;

    public function __construct($type) {
        $this->type = new ReflectionClass($type);
    }

    public function collectMetadata() {
        // Get docComment
        $docComment = $type->getDocComment();

        // Any named exports mentioned?
        if (strpos($docComment, '@export ') !== false) {
            // Search for @export contents
            $commentLines = explode("\n", $docComment);
            foreach ($commentLines as $commentLine) {
                if (strpos($commentLine, '@export ') !== false) {
                    $namedExport = trim(substr($commentLine, strpos($commentLine, '@export') + 8));
                    $this->foundExportNames[] = $namedExport;
                }

                if (strpos($commentLine, '@export-metadata ') !== false) {
                    $namedExportMetadata = trim(substr($commentLine, strpos($commentLine, '@export-metadata') + 17));
                    $foundMetadata[] = $namedExportMetadata;
                }
            }
        }

        // Build return value
        $this->returnValue = array();
        foreach ($this->foundExportNames as $foundExportName) {
            $this->returnValue[$foundExportName] = new MEF_Export($className, $foundMetadata, 'class');
        }

        // Add member information
        $this->returnValue = array_merge(
                        $this->returnValue,
                        $this->processExportsOnClassMembers($className, $foundMetadata)
        );

        // Return
        return $this->returnValue;
    }
}

/**
 * 
 *
 * @author Virtualidad
 */
class MEFContainer extends MEF_Container_Default {

    protected function _processExportsOnClass($className) {
        return parent::_processExportsOnClass($className);
    }

    protected function _processExportsOnClassMembers($className,
            $parentMetadata = array()) {
        return parent::_processExportsOnClassMembers($className, $parentMetadata);
    }

    protected function _processExportsOnMember($className, $member,
            $parentMetadata = array()) {
        return parent::_processExportsOnMember($className, $member, $parentMetadata);
    }

}

?>
